package dao;

import hbt.HibernateUtil;
import negocio.Plato;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class PlatoDAO {

	private static PlatoDAO instancia = null;
	private static SessionFactory sf = null;
	
	public PlatoDAO()
	{
		
	}
	public static PlatoDAO getInstancia()
	{
		if (instancia==null)
		{
			sf = HibernateUtil.getSessionFactory();
			instancia = new PlatoDAO();
		}
		return instancia;
	}
	
	public void grabarPlato(Plato p)
	{
		Session s = sf.openSession();
		s.beginTransaction();
		s.persist(p);
		s.flush();
		s.getTransaction().commit();
		s.close();
	}

	public Plato buscarPlato(int nroPlato) {
		Session session = sf.openSession();
		Plato p = new Plato();
		p.setNroPlato(nroPlato);
		session.load(p, p.getNroPlato());			
		session.close();
		return p;
	}
}
